package com.higgins.lawapp.client.settings.handlers;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.higgins.lawapp.client.settings.model.DataSourceModel;

public class ElementNameHandler implements KeyUpHandler {
//	private final ResearchServiceAsync researchService = GWT.create(ResearchService.class);	
	private TextBox textbox;
	private Label errorLabel;
	private DataSourceModel dataSourceModel;
	
	public ElementNameHandler(TextBox textbox, Label errorLabel, DataSourceModel dataSourceModel)	{
		this.textbox = textbox;
		this.errorLabel = errorLabel;
		this.dataSourceModel = dataSourceModel;
	}
	
	public void onKeyUp(KeyUpEvent event) {
		if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
			dataSourceModel.setElementName(textbox.getText());
		}
	}
	/*
	private void receiveNameFromServer() {
		researchService.getResearch( 
				new AsyncCallback<Data>() {
					public void onFailure(Throwable caught) {
						errorLabel.setText("Failure to Retrieve Name From Server!!");
					}

					public void onSuccess(Data data) {
						errorLabel.setText(data.getText() + "\n" + data.getUser() + "\n" + data.getAge().toString());
					}
				});
	}
	
	private void sendNameToServer(String text) {
		Data myData = new Data();
		myData.setText(text);
		myData.setUser("Patrick Higgins");
		myData.setAge(new Double(33.0));
		researchService.setResearch(myData, 
				new AsyncCallback<String>() {
					public void onFailure(Throwable caught) {
						errorLabel.setText("Failure to Send Name to Server!!");
					}

					public void onSuccess(String result) {
						errorLabel.setText(result.toString());
					}
				});
	}		*/

}